﻿@model DHQGHN.PM2.Models.Online.Khaisinh3Model

<script>
    @functions{
        public string GetAntiForgeryToken()
        {
            string cookieToken, formToken;
            AntiForgery.GetTokens(null, out cookieToken, out formToken);
            return cookieToken + "," + formToken;
        }
    };
    jQuery(function ($) {
        Tooltip();
        $("#divLoading").show();
        $("#btnNext").attr("disabled", "disabled");
        $("#btnBack").attr("disabled", "disabled");
        Checkngay("DAYKS3");
        Checkthang("MONTHKS3");
        Checknam("YEARKS3");
        Checkcmnd("MOTHER_IDCARD_NUM");
        codedob = $("#CODEDOB").val();
        tinhdob = $("#CODEDOB").val().substring(0, 2);
        huyennpdob = $("#CODEDOB").val().substring(0, 5);
        if (codedob != "") {
            $("#TINHKS3").val(tinhdob);
        }
        if ($("#TINHKS3").val() != "-1") {
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS3").val(),
                    level: '2'
                },
                success: function (states) {
                    $("#HUYENKS3").append('<option value="' + '-1' + '">' +
                '-- Chọn Huyện --' + '</option>');
                    $.each(states, function (i, state) {
                        $("#HUYENKS3").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function () {
                    $("#HUYENKS3").val(huyennpdob);
                    $("#XAKS3").empty();
                    $("#XAKS3").append('<option value="' + '-1' + '">' +
                        '-- Chọn Xã --' + '</option>');
                    $.ajax({
                        type: 'POST',
                        url: '@Url.Action("GetAdministrativeUnit1")',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        dataType: 'json',

                        data: {
                            code: $("#HUYENKS3").val(),
                            level: '3'
                        },
                    
                        success: function (states) {
                          
                            $.each(states, function (i, state) {
                                $("#XAKS3").append('<option value="' + state.Value + '">' +
                                    state.Text + '</option>');

                               
                            });

                        },
                        complete: function () {
                            $("#XAKS3").val(codedob);
                            Check();
                        },
                        error: function (ex) {
                            alert('Failed to retrieve states.' + ex);
                        }
                    });
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
        }
        else {
            $("#HUYENKS3").append('<option value="' + '-1' + '">' +
                '-- Chọn Huyện --' + '</option>');
            $("#XAKS3").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
        }
        $("#TINHKS3").change(function () {
            $("#divLoading").show();
            $("#HUYENKS3").empty();
            $("#XAKS3").empty();
            $("#HUYENKS3").append('<option value="' + '-1' + '">' +
                 '-- Chọn Huyện --' + '</option>');
            $("#XAKS3").append('<option value="' + '-1' + '">' +
                 '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")',
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#TINHKS3").val(),
                    level: '2'
                },
                success: function (states) {
                    $.each(states, function (i, state) {
                        $("#HUYENKS3").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                    });

                },
                complete: function (states) {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        })
        $("#HUYENKS3").change(function () {
            $("#divLoading").show();
            $("#XAKS3").empty();
            $("#XAKS3").append('<option value="' + '-1' + '">' +
                '-- Chọn Xã --' + '</option>');
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetAdministrativeUnit1")', 
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                dataType: 'json',

                data: {
                    code: $("#HUYENKS3").val(),
                    level: '3'
                },
      
                success: function (states) {
                  
                    $.each(states, function (i, state) {
                        $("#XAKS3").append('<option value="' + state.Value + '">' +
                             state.Text + '</option>');
                     
                    });

                },
                complete: function () {
                    $("#divLoading").hide();
                },
                error: function (ex) {
                    alert('Failed to retrieve states.' + ex);
                }
            });
            return false;
        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            method: 'GET',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            data: { 'tablename': 'COUNTRY' },
            success: function (data, textStatus, jqXHR) {
                $(".MOTHER_COUNTRY_ID").append('<option value="">' +
               '-- Chọn Quốc tịch --' + '</option>');
                $.each(data, function (i, item) {
                    $(".MOTHER_COUNTRY_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');
                  
                });
                $(".MOTHER_COUNTRY_ID").val("@Model.MOTHER_COUNTRY_ID");
            },
            complete: function () {
                Check();
            }

        });
        $.ajax({
            url: '@Url.Action("GetAllByListName")',
            dataType: 'json',
            method: 'GET',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            data: { 'tablename': 'ETHNIC' },
            success: function (data, textStatus, jqXHR) {
                $(".MOTHER_ETHNIC_ID").append('<option value="">' +
             '-- Chọn Dân tộc --' + '</option>');
                $.each(data, function (i, item) {
                    $(".MOTHER_ETHNIC_ID").append('<option value="' + item.CodeID + '">' +
                         item.Name + '</option>');
                    
                });
                $(".MOTHER_ETHNIC_ID").val(@Model.MOTHER_ETHNIC_ID);
            },
            complete: function () {
                Check();
            }

        });

    });
    function ClickButton(Next) {
        $("#divLoading").show();
        var ngay = $("#DAYKS3").val();
        var thang = $("#MONTHKS3").val();
        var nam = $("#YEARKS3").val();
        xa = $("#XAKS3").val();
        if (xa == "-1") {
            xa = "";
        }
        var dataSend = {
            'HOUSEHOLD_ID': $("#HOUSEHOLD_ID").val(),
            'RESIDENT_ID': $("#RESIDENT_ID").val(),
            'MOTHER_LNAME': $("#MOTHER_LNAME").val(),
            'MOTHER_MNAME': $("#MOTHER_MNAME").val(),
            'MOTHER_FNAME': $("#MOTHER_FNAME").val(),
            'MOTHER_DOB': nam + thang + ngay,
            'MOTHER_ETHNIC_ID': $(".MOTHER_ETHNIC_ID").val(),
            'MOTHER_COUNTRY_ID': $(".MOTHER_COUNTRY_ID").val(),
            'MOTHER_RPOB_ADM_UNIT_ID': xa,
            'MOTHER_IDCARD_NUM': $("#MOTHER_IDCARD_NUM").val(),
            'NEXT': Next,

        };
        var jqXHR = $.ajax({
            url: '@Url.Action("Khaisinh3","Online")',
            dataType: 'html',
            headers: {
                'VerificationToken': '@GetAntiForgeryToken()'
            },
            method: 'post',
            cache: false,
            data: dataSend,
            success: function myfunctionSuccess(data, textStatus, jqXHR) {
                if (Next == "2") {
                    $('#formLogin').html(data);
                }
                else {
                    $('#loadPartial').html(data);
                }
            },
            complete: function (jqXHR, textStatus) {
                $("#divLoading").hide();
                $("#btnNext").removeAttr("disabled");
                $("#btnBack").removeAttr("disabled");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Có lỗi xảy ra trong quá trình lưu thông tin: ' + errorThrown);
            },

        });
    }
    function Check() {
        var COUNTRY_ID = $(".MOTHER_COUNTRY_ID").val();
        var ETHNIC_ID = $(".MOTHER_ETHNIC_ID").val();
        var NP_ADM_UNIT_ID = $("#XAKS3").val();
        if (NP_ADM_UNIT_ID == "-1") {
            NP_ADM_UNIT_ID = "";
        }
        var coun = $("#MOTHER_COUNTRY_ID").val();
        if (COUNTRY_ID == coun && ETHNIC_ID == "@Model.MOTHER_ETHNIC_ID" && NP_ADM_UNIT_ID == codedob) {
            $("#divLoading").hide();
            $("#btnNext").removeAttr("disabled");
            $("#btnBack").removeAttr("disabled");
        }
        else {
            $("#divLoading").show();
            $("#btnNext").attr("disabled", "disabled");
            $("#btnBack").attr("disabled", "disabled");
        }

    };
    $("#btnNext").click(function (event, giatri) {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            if (giatri != null) {
                ClickButton(giatri);
            }
            else {
                if (Checkdatetime("DAYKS3", "MONTHKS3", "YEARKS3") == 0) {
                    ClickButton(1);
                }
            }
        }
    });
    $("#btnBack").click(function () {
        if (checkhtml()) {
            alert("Dữ liệu nhập không được có ký tự '<' ở đầu.");
        } else {
            ClickButton(0);
        }
    });

</script>
<style>
    .ui-tooltip, .arrow:after {
        background: #FAFAD2;
    }

    .ui-tooltip {
        color: black;
        font-size: 12px;
    }

    .arrow {
        width: 70px;
        height: 16px;
        overflow: hidden;
        position: absolute;
        left: 50%;
        margin-left: -35px;
        bottom: -16px;
    }

        .arrow.top {
            top: -16px;
            bottom: auto;
        }

        .arrow.left {
            left: 20%;
        }

        .arrow:after {
            content: "";
            position: absolute;
            left: 20px;
            top: -20px;
            width: 25px;
            height: 25px;
            box-shadow: 6px 5px 9px -9px black;
            -webkit-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            transform: rotate(45deg);
        }

        .arrow.top:after {
            bottom: -20px;
            top: auto;
        }
</style>
<div class="noidung-nhaponline">
    <div class="login-fields2">
        <p style="float: left; padding-right: 5px; vertical-align: top;">
            <img src="../Images/rt_arrow.gif">
        <p>Thông tin Mẹ đẻ:</p>
    </div>
    <div class="row row-online-table-head">
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_LNAME, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.MOTHER_LNAME, new { @class = "form-control ", MaxLength = 50, Tabindex = 1 })
        </div>
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_IDCARD_NUM, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.MOTHER_IDCARD_NUM, new { @class = "form-control ", MaxLength = 12, Tabindex = 7, @title = @Html.ToolTipMessageFor(m => m.MOTHER_IDCARD_NUM) })
        </div>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_MNAME, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.MOTHER_MNAME, new { @class = "form-control ", MaxLength = 150, Tabindex = 2 })
        </div>
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_COUNTRY_ID, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            <select class="MOTHER_COUNTRY_ID form-control" tabindex="8"></select>
        </div>
    </div>
    <div class="row row-online-table1">

        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_FNAME, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.MOTHER_FNAME, new { @class = "form-control ", MaxLength = 50, Tabindex = 3 })
        </div>
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_ETHNIC_ID, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            <select class="MOTHER_ETHNIC_ID form-control " style="width:75%;" tabindex="9"></select>
        </div>
    </div>
    <div class="row row-online-table1">
        <div class="col-md-2">
            @Html.LabelFor(model => model.MOTHER_DOB, new { @class = "control-label " })
        </div>
        <div class="col-md-4">
            @Html.TextBoxFor(model => model.DAYKS3, new { @class = "form-control", style = "width: 20%; display: inline;", MaxLength = 2, Tabindex = 4, @title = @Html.ToolTipMessageFor(m => m.DAYKS3) })/@Html.TextBoxFor(model => model.MONTHKS3, new { @class = "form-control", style = "width: 20%; display: inline;", MaxLength = 2, Tabindex = 5, @title = @Html.ToolTipMessageFor(m => m.MONTHKS3) })/@Html.TextBoxFor(model => model.YEARKS3, new { @class = "form-control", style = "width: 40%; display: inline;", MaxLength = 4, Tabindex = 6, @title = @Html.ToolTipMessageFor(m => m.YEARKS3) })
        </div>

    </div>
    <div class="row row-online-table1">
        <div class="col-md-3 widthlabelTinhHuyenXa">
            @Html.LabelFor(model => model.MOTHER_RPOB_ADM_UNIT_ID, new { @class = "control-label " })
        </div>
        <div class="col-md-3 widthTinhHuyenXa">
            @Html.DropDownList("TINHKS3", ViewData["DISTRICT_CODE"] as List<SelectListItem>, new { @class = "form-control", Tabindex = 10, @title = @Html.ToolTipMessageFor(m => m.TINH) })

        </div>
        <div class="col-md-3 widthTinhHuyenXa">
            @Html.DropDownList("HUYENKS3", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", Tabindex = 11, @title = @Html.ToolTipMessageFor(m => m.HUYEN) })
        </div>
        <div class="col-md-3 widthTinhHuyenXa">
            @Html.DropDownList("XAKS3", new SelectList(string.Empty, "Value", "Text"), new { @class = "form-control", Tabindex = 12, @title = @Html.ToolTipMessageFor(m => m.XA) })
        </div>
    </div>
    <div>
        @Html.HiddenFor(model => model.RESIDENT_ID)
        @Html.HiddenFor(model => model.HOUSEHOLD_ID)
        @Html.HiddenFor(model => model.CODEDOB)
        @Html.HiddenFor(model => model.MOTHER_COUNTRY_ID)
    </div>
    <center>
        <input type="button" class="btn btn-small btn-small_online btn-success buttonClick" id="btnBack" tabindex="13" value="<< Quay lại">
        <input type="button" class="btn btn-small btn-small_online btn-success buttonClick" id="btnNext" tabindex="14" value="Tiếp tục >>">
    </center>
</div>






